﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2.Event
{
    public class DoSomethingService : IDoSomethingService
    {
        private readonly IEventBus _eventBus;
        public DoSomethingService(IEventBus eventBus)
        {
            _eventBus = eventBus;

            //订阅
            //eventBus.Subscribe<DoSomethingEvent, DoSomethingEventHandler>();
        }

        public async Task DoSomethingAsync(string receiver, string subject, string body)
        {
            //这里可以调用真实的邮件发送服务API
            Console.WriteLine($"Emailsentto{receiver}withsubject{subject}");

            //假设这里处理了一些逻辑，并决定发送邮件
            var emailEvent = new DoSomethingEvent(subject, body, receiver);
            _eventBus.Publish(emailEvent);
        }
    }
}
